package com.crm.base.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crm.base.domain.LoginUser;
import com.crm.base.domain.User;
import com.crm.base.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private UserMapper mapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        User user = mapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUserName, s));

        return new LoginUser(user);
    }
}
